rot :: String -> [String]
rot [] = []
rot [x] = [[x]]
rot (x:xs) = r : rot r
    where r = xs ++ [x]
    
applyRot :: String -> String
applyRot xs = unwords $ take l $ rot xs
    where l = length xs
           
main = do
    c <- getContents
    let l = drop 1 $ lines c
    putStr $ unlines $ map applyRot l
    